package com.amlyc.demo2;

import com.amlyc.demo1.TestThread4;

public class TestStop implements Runnable {
    private boolean flag = true;
    @Override
    public void run() {
        int i = 0;
        flag = true;
        while (flag) {
            System.out.printf("run..%d\n",(i++));
        }
    }
    public void stop(){
        this.flag=false;
    }

    public static void main(String[] args) {

        TestStop testStop = new TestStop();
        new Thread(testStop).start();
        for (int i = 0; i < 1000; i++) {
            if (i == 900) {
                testStop.stop();
                System.out.println("stop");
            }
        }
    }
}
